
import { myRequest } from './http.js'
let path = 'api/services/app/'
let apiShop = {
	// 首页搜索
	async searchReturnPages(data, callback) {
		let pageIndex = data.pageIndex
		let pageSize = data.pageSize
		let data2 = { SkipCount: (pageIndex - 1) * pageSize, MaxResultCount: pageSize, tabType: data.tabType, sort: data.sort, searchKey: data.searchKey }
		let res =  await myRequest({ url: path + 'HomePageAppservice/SearchReturnPages', method: 'POST', data: data2 || ''  })
		callback&&callback(res)
	},
	
	// 获取商品分类
	async getCommodityList(data, callback) {
		let res =  await myRequest({ url: path + 'Commodity/GetCommodityList', method: 'GET', data: data || ''  })
		callback&&callback(res)
	},
	
	// 商品分类ID获取商品列表
	async getCommodityPagesByType(data, callback) {
		let {pageIndex, pageSize, typeId} = data
		let data2 = { SkipCount: (pageIndex - 1) * pageSize, MaxResultCount: pageSize, TypeId: typeId }
		let res =  await myRequest({ url: path + 'Commodity/GetCommodityPagesByType', method: 'GET', data: data2 || ''  })
		callback&&callback(res)
	},
	
	// 商品详情
	async commodityDetailsById(data, callback) {
		let res =  await myRequest({ url: path + 'Commodity/CommodityDetailsById', method: 'POST', data: data || '' })
		callback&&callback(res)
	},
	
	// 加入购物车
	async addToCart(data, callback) {
		let res =  await myRequest({ url: path + 'ShoppingCart/AddToCart', method: 'POST', data: data || '' })
		callback&&callback(res)
	},
	
	// 购物车列表
	async getCommodityFromCart(data, callback) {
		let res =  await myRequest({ url: path + 'ShoppingCart/GetCommodityFromCart', method: 'GET', data: data || '' })
		callback&&callback(res)
	},
	
	// 购物车移除商品
	async removeFromCart(data, callback) {
		let res =  await myRequest({ url: path + 'ShoppingCart/RemoveFromCart', method: 'POST', data: data || '' })
		callback&&callback(res)
	},
	
	// 更改购物车数量
	async editShoppingCartItem(data, callback) {
		let res =  await myRequest({ url: path + 'ShoppingCart/EditShoppingCartItem', method: 'POST', data: data || '' })
		callback&&callback(res)
	},
	
	// 下单页用户优惠券和抵扣豆数据
	async getDiscount(data, callback) {
		let res =  await myRequest({ url: path + 'Commodity/GetDiscount', method: 'GET', data: data || '' })
		callback&&callback(res)
	},
}

export { apiShop }